Skip to content

✨ Adds new condition to VirtualMachine to the expose state of metadata+userdata #167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 10, 2023

Conversation

srm09
Copy link
Contributor

@srm09 srm09 commented Jun 23, 2023

What does this PR do, and why is it needed?
Adds a new condition to the VirtualMachine CR to expose the state of the metadata+userdata.

Which issue(s) is/are addressed by this PR?:
Fixes #148

Are there any special notes for your reviewer:

Please add a release note if necessary:

Adds new condition to VirtualMachine to the expose state of metadata+userdata

@github-actions github-actions bot added testing-needed-e2e-fast size/L Denotes a PR that changes 100-499 lines. labels Jun 23, 2023
@srm09 srm09 force-pushed the vm-condition/metadata-limit-exceeded branch 2 times, most recently from 36ab117 to 68a740a Compare June 26, 2023 16:55
Copy link
Contributor

@zyiyi11 zyiyi11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM. I like the ErrWithReason implementation. Thanks

@srm09 srm09 force-pushed the vm-condition/metadata-limit-exceeded branch from 68a740a to 176a219 Compare June 28, 2023 05:05
Copy link
Contributor

@sreyasn sreyasn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change LGTM!. Thanks @srm09.

@@ -10,6 +10,28 @@ import (
"github.com/vmware-tanzu/vm-operator/api/v1alpha2/common"
)

const (
// VirtualMachineMetadataReadyCondition documents the state of the metadata passed to the VirtualMachine.
VirtualMachineMetadataReadyCondition = "VirtualMachineMetadataReady"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we have a concept of "metadata" in v1a2? It is called VirtualMachineBootstrapSpec. Or maybe this is more nuanced and I am missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Atm I am just trying to replicate the reasons in v1a2 types, I can add a TODO and get back to updating the description on this one once we make the switch to the new types.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment which states the intent of adding these and the future updates to these types.

// cannot be found.
VirtualMachineMetadataNotFoundReason = "VirtualMachineMetadataNotFound"

// VirtualMachineMetadataInvalidReason (Severity=Error) documents that the supplied Cloud Init metadata is invalid.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

specified Cloud Init metadata

This is slightly confusing, right? We chose to call it metadata -- but really, it is userdata that is specified by a field called vmMetadata.

I would reword this a little bit to make it clear that this is talking about the vmMetadata resource specified -- and that this is only applicable if the transport type is CloudInit. Same for the type below. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand your point, my longer term thought behind this one was to use it for all types of metadata regardless the type of transport we are aiming at. I will update the comments on this one to remove the coupling with CloudInit metadata and make it general purpose so as to use it broadly in the future.

@@ -72,6 +72,9 @@ const (
CloudInitGuestInfoUserdata = "guestinfo.userdata"
CloudInitGuestInfoUserdataEncoding = "guestinfo.userdata.encoding"

// CloudInitGuestInfoMaxSize the maximum allowed size for cloud init metadata.
CloudInitGuestInfoMaxSize = 64 * 1024
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious: is there a way to fetch this at a cluster level? That way, we don't have to maintain this bespoke const in our code and worry about it falling out of sync with what is enforced at the Guest level.

If not, we should at least call out in comments that this is enforced by the infra (ESXi) (and maybe link a public KB) so readers are not wondering how we arrived at this const.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was mentioned in the GH issue linked to the PR, but makes sense to call it explicitly here. Added the reference link on where this size value is defined.

})
})

Context("With cloud init metadata + userdata exceeding the maximum size", func() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a valid scenario though? IIRC, the limit is enforced by the size of the value of each GuestInfo key. If both of the keys individually are less than the limit, then we should be fine?

VirtualMachineMetadataNotFoundReason = "VirtualMachineMetadataNotFound"

// VirtualMachineMetadataInvalidReason (Severity=Error) documents that the supplied Cloud Init metadata is invalid.
VirtualMachineMetadataInvalidReason = "VirtualMachineMetadataInvalid"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Part of me wants to reserve the "Invalid" key here because it feels too broad. It might be helpful in future when we decide to validating the specified user-data itself (e.g., that it's format is correct).
WDYT about renaming it VirtualMachineMetadataFormatInvalid (or something similar that indicates that the encode/decode fails -- because that's what we are really validating here)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK, this makes sense. Invalid sounds too broad, and we can in the future have more pointed reasons to include other error scenarios.

@srm09 srm09 force-pushed the vm-condition/metadata-limit-exceeded branch from 176a219 to ce7874b Compare July 5, 2023 22:33
Copy link
Contributor Author

@srm09 srm09 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aruneshpa made the changes you asked for.

// cannot be found.
VirtualMachineMetadataNotFoundReason = "VirtualMachineMetadataNotFound"

// VirtualMachineMetadataInvalidReason (Severity=Error) documents that the supplied Cloud Init metadata is invalid.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand your point, my longer term thought behind this one was to use it for all types of metadata regardless the type of transport we are aiming at. I will update the comments on this one to remove the coupling with CloudInit metadata and make it general purpose so as to use it broadly in the future.

VirtualMachineMetadataNotFoundReason = "VirtualMachineMetadataNotFound"

// VirtualMachineMetadataInvalidReason (Severity=Error) documents that the supplied Cloud Init metadata is invalid.
VirtualMachineMetadataInvalidReason = "VirtualMachineMetadataInvalid"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK, this makes sense. Invalid sounds too broad, and we can in the future have more pointed reasons to include other error scenarios.

@@ -10,6 +10,28 @@ import (
"github.com/vmware-tanzu/vm-operator/api/v1alpha2/common"
)

const (
// VirtualMachineMetadataReadyCondition documents the state of the metadata passed to the VirtualMachine.
VirtualMachineMetadataReadyCondition = "VirtualMachineMetadataReady"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Atm I am just trying to replicate the reasons in v1a2 types, I can add a TODO and get back to updating the description on this one once we make the switch to the new types.

@@ -10,6 +10,28 @@ import (
"github.com/vmware-tanzu/vm-operator/api/v1alpha2/common"
)

const (
// VirtualMachineMetadataReadyCondition documents the state of the metadata passed to the VirtualMachine.
VirtualMachineMetadataReadyCondition = "VirtualMachineMetadataReady"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment which states the intent of adding these and the future updates to these types.

@@ -72,6 +72,9 @@ const (
CloudInitGuestInfoUserdata = "guestinfo.userdata"
CloudInitGuestInfoUserdataEncoding = "guestinfo.userdata.encoding"

// CloudInitGuestInfoMaxSize the maximum allowed size for cloud init metadata.
CloudInitGuestInfoMaxSize = 64 * 1024
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was mentioned in the GH issue linked to the PR, but makes sense to call it explicitly here. Added the reference link on where this size value is defined.

@github-actions
Copy link

github-actions bot commented Jul 5, 2023

Code Coverage

Package Line Rate Health
github.com/vmware-tanzu/vm-operator/controllers 0%
github.com/vmware-tanzu/vm-operator/controllers/contentlibrary/clustercontentlibraryitem 83%
github.com/vmware-tanzu/vm-operator/controllers/contentlibrary/contentlibraryitem 84%
github.com/vmware-tanzu/vm-operator/controllers/contentlibrary/contentsource 87%
github.com/vmware-tanzu/vm-operator/controllers/contentlibrary/utils 97%
github.com/vmware-tanzu/vm-operator/controllers/infracluster 75%
github.com/vmware-tanzu/vm-operator/controllers/infraprovider 75%
github.com/vmware-tanzu/vm-operator/controllers/providerconfigmap 74%
github.com/vmware-tanzu/vm-operator/controllers/util/encoding 73%
github.com/vmware-tanzu/vm-operator/controllers/util/remote 41%
github.com/vmware-tanzu/vm-operator/controllers/virtualmachine 46%
github.com/vmware-tanzu/vm-operator/controllers/virtualmachineclass 31%
github.com/vmware-tanzu/vm-operator/controllers/virtualmachinepublishrequest 83%
github.com/vmware-tanzu/vm-operator/controllers/virtualmachineservice 82%
github.com/vmware-tanzu/vm-operator/controllers/virtualmachineservice/providers 96%
github.com/vmware-tanzu/vm-operator/controllers/virtualmachineservice/providers/simplelb 66%
github.com/vmware-tanzu/vm-operator/controllers/virtualmachineservice/utils 83%
github.com/vmware-tanzu/vm-operator/controllers/virtualmachinesetresourcepolicy 80%
github.com/vmware-tanzu/vm-operator/controllers/volume 87%
github.com/vmware-tanzu/vm-operator/controllers/webconsolerequest 72%
github.com/vmware-tanzu/vm-operator/pkg/builder 70%
github.com/vmware-tanzu/vm-operator/pkg/conditions 90%
github.com/vmware-tanzu/vm-operator/pkg/context 0%
github.com/vmware-tanzu/vm-operator/pkg/context/fake 100%
github.com/vmware-tanzu/vm-operator/pkg/lib 79%
github.com/vmware-tanzu/vm-operator/pkg/manager 82%
github.com/vmware-tanzu/vm-operator/pkg/metrics 91%
github.com/vmware-tanzu/vm-operator/pkg/patch 78%
github.com/vmware-tanzu/vm-operator/pkg/prober 92%
github.com/vmware-tanzu/vm-operator/pkg/prober/context 100%
github.com/vmware-tanzu/vm-operator/pkg/prober/fake 85%
github.com/vmware-tanzu/vm-operator/pkg/prober/fake/probe 83%
github.com/vmware-tanzu/vm-operator/pkg/prober/fake/worker 88%
github.com/vmware-tanzu/vm-operator/pkg/prober/probe 83%
github.com/vmware-tanzu/vm-operator/pkg/prober/worker 86%
github.com/vmware-tanzu/vm-operator/pkg/record 89%
github.com/vmware-tanzu/vm-operator/pkg/topology 85%
github.com/vmware-tanzu/vm-operator/pkg/util 83%
github.com/vmware-tanzu/vm-operator/pkg/util/kube 89%
github.com/vmware-tanzu/vm-operator/pkg/util/vsphere/vm 74%
github.com/vmware-tanzu/vm-operator/pkg/vmprovider/fake 80%
github.com/vmware-tanzu/vm-operator/pkg/vmprovider/providers/vsphere 72%
github.com/vmware-tanzu/vm-operator/pkg/vmprovider/providers/vsphere/client 74%
github.com/vmware-tanzu/vm-operator/pkg/vmprovider/providers/vsphere/clustermodules 85%
github.com/vmware-tanzu/vm-operator/pkg/vmprovider/providers/vsphere/config 85%
github.com/vmware-tanzu/vm-operator/pkg/vmprovider/providers/vsphere/contentlibrary 71%
github.com/vmware-tanzu/vm-operator/pkg/vmprovider/providers/vsphere/credentials 100%
github.com/vmware-tanzu/vm-operator/pkg/vmprovider/providers/vsphere/instancestorage 92%
github.com/vmware-tanzu/vm-operator/pkg/vmprovider/providers/vsphere/internal 0%
github.com/vmware-tanzu/vm-operator/pkg/vmprovider/providers/vsphere/network 87%
github.com/vmware-tanzu/vm-operator/pkg/vmprovider/providers/vsphere/placement 83%
github.com/vmware-tanzu/vm-operator/pkg/vmprovider/providers/vsphere/resources 47%
github.com/vmware-tanzu/vm-operator/pkg/vmprovider/providers/vsphere/session 83%
github.com/vmware-tanzu/vm-operator/pkg/vmprovider/providers/vsphere/storage 77%
github.com/vmware-tanzu/vm-operator/pkg/vmprovider/providers/vsphere/test 98%
github.com/vmware-tanzu/vm-operator/pkg/vmprovider/providers/vsphere/vcenter 80%
github.com/vmware-tanzu/vm-operator/pkg/vmprovider/providers/vsphere/virtualmachine 87%
github.com/vmware-tanzu/vm-operator/pkg/webconsolevalidation 53%
github.com/vmware-tanzu/vm-operator/webhooks 0%
github.com/vmware-tanzu/vm-operator/webhooks/common 100%
github.com/vmware-tanzu/vm-operator/webhooks/persistentvolumeclaim 0%
github.com/vmware-tanzu/vm-operator/webhooks/persistentvolumeclaim/validation 95%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachine 0%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachine/v1alpha1 0%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachine/v1alpha1/mutation 86%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachine/v1alpha1/validation 94%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachineclass 0%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachineclass/v1alpha1 0%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachineclass/v1alpha1/mutation 59%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachineclass/v1alpha1/validation 89%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachinepublishrequest 0%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachinepublishrequest/v1alpha1 0%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachinepublishrequest/v1alpha1/validation 92%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachineservice 0%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachineservice/v1alpha1 0%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachineservice/v1alpha1/mutation 62%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachineservice/v1alpha1/validation 91%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachinesetresourcepolicy 0%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachinesetresourcepolicy/v1alpha1 0%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachinesetresourcepolicy/v1alpha1/mutation 62%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachinesetresourcepolicy/v1alpha1/validation 89%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachinewebconsolerequest 0%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachinewebconsolerequest/v1alpha1 0%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachinewebconsolerequest/v1alpha1/validation 92%
Summary 79% (6177 / 7784)

Minimum allowed line rate is 60%

Copy link
Contributor

@aruneshpa aruneshpa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@srm09 srm09 added the testing-done-e2e-fast Indicates the fast, low-cost e2e testing has been used to validate a PR label Jul 10, 2023
@srm09 srm09 merged commit 3cae82b into vmware-tanzu:main Jul 10, 2023
@srm09 srm09 deleted the vm-condition/metadata-limit-exceeded branch July 10, 2023 22:44
@@ -261,6 +301,12 @@ func customizeCloudInit(
}

if err != nil {
errWithReason := err.(ErrWithReason)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was supposed to be errWithReason := err.(*ErrWithReason)
Will try to add unit tests for this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-not-required size/L Denotes a PR that changes 100-499 lines. testing-done-e2e-fast Indicates the fast, low-cost e2e testing has been used to validate a PR testing-needed-e2e-fast
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feature: Use condition to indicate when Cloud-Init metadata/userdata exceeds allowed size
6 participants